package com.whale.cloud.util.solr;

import com.whale.cloud.util.solr.NewSolrRead;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;

/** Created by Abel on 2017/5/25. */
@Configuration
@EnableSolrRepositories(multicoreSupport = true)
@EnableConfigurationProperties(SolrProperties.class)
@Log4j2
public class SolrAutoConfiguration {

  @Autowired SolrProperties solrProperties;
  //
  //    public void setSolrProperties(SolrProperties solrProperties) {
  //        this.solrProperties = solrProperties;
  //    }
  //
  //    @Bean(name = "cloudSolrClient")
  //    @Qualifier("cloudSolrClient")
  //    public CloudSolrClient solrClient() throws MalformedURLException {
  //        return new SolrClient().NewSolrRead(solrProperties.getCollection());
  //    }

  @Bean
  public NewSolrRead getSolrClient() {
    log.info("----solrClient-----" + solrProperties.getZkHost());
    //    SolrClient solrClient = new SolrClient();
    //    log.info("----solrClient-----" + solrProperties.getCollection());
    //    solrClient.setSolrProperties(solrProperties);
    //    log.info("----solrClient-----" + solrProperties.getCollection_coupon());
    return NewSolrRead.getInstance();
  }

  @Bean
  public SolrClient getCloudSolrClient() {
    log.info("----Client-----" + solrProperties.getZkHost());
    SolrClient solrClient = new SolrClient();
    solrClient.setSolrProperties(solrProperties);
    return solrClient;
  }

  //  @Bean(name = "Client")
  //  public org.apache.solr.client.solrj.impl.CloudSolrClient getCloudSolrClient() {
  //    log.info("----Client-----" + solrProperties.getZkHost());
  //    CloudSolrClient solrClient = new CloudSolrClient();
  //    solrClient.setSolrProperties(solrProperties);
  //    return solrClient.getCloudSolrClient(solrProperties.getCollection_vip());
  //  }
}
